package moodish.dummy;

import java.util.LinkedList;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

import moodish.comm.ServerComm;
import moodish.comm.ServerSideMessage;
import moodish.comm.ServerSideMessage.Type;
import moodish.server.SSM;

public class ServerCommDummy implements ServerComm {
	
	
	private BlockingQueue<SSM> msg = new ArrayBlockingQueue<SSM>(100);
	
	@Override
	public void start() {
		Thread t = new Thread(new Runnable() {
			
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
					msg.put(new SSM(Type.CLIENT_CONNECTED, "Maria", null));
					
					Thread.sleep(1000);
					msg.put(new SSM(Type.FRIENDSHIP, "Maria", "Joao"));
					
					Thread.sleep(1000);
					msg.put(new SSM(Type.MOODISH_MESSAGE, "Maria", "Moodish Message"));
					
					
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
		t.start();
		
	}

	@Override
	public boolean hasNextMessage() {
		// TODO Auto-generated method stub
		return msg.isEmpty();
	}

	@Override
	public ServerSideMessage getNextMessage() {
		// TODO Auto-generated method stub
		try {
			return msg.take();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public void sendNewFriendship(String toNickname, String newFriendship) {
		System.out.println("New friendship"+toNickname + " " + newFriendship);
		
	}

	@Override
	public void sendError(String toNickname, String error) {
		// TODO Auto-generated method stub
		System.out.println("Error"+toNickname + " " + error);
	}

	@Override
	public boolean clientIsConnected(String nickname) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void sendClientConnected(String toNickname, String userConnected) {
		// TODO Auto-generated method stub
		System.out.println("Client connect "+toNickname + " " + userConnected);
	}

	@Override
	public void sendClientDisconnected(String toNickname, String userDisconnected) {
		// TODO Auto-generated method stub
		System.out.println("Client Disconnect "+toNickname + " " + userDisconnected);
	}

	@Override
	public void disconnectClient(String nickname) {
		// TODO Auto-generated method stub
		System.out.println("Disconnect "+nickname);
	}

	@Override
	public void sendMoodishMessage(String fromNicename, String toNickname,
			String message) {
		// TODO Auto-generated method stub
		System.out.println("Moodish Message" +fromNicename+ " " + toNickname + " " + message);
	}

	@Override
	public void sendNewUnfriendship(String toNickname, String newFriendship) {
		// TODO Auto-generated method stub
		
	}
}
